package com.doit.day03

import scala.beans.BeanProperty
import scala.util.Sorting

object _01_比较器 {
  def main(args: Array[String]): Unit = {
    val arr: Array[ScalaOrder] = Array(
      ScalaOrder(1, 1, 1, "1", 1.0, 1),
      ScalaOrder(2, 2, 2, "2", 2.0, 2),
      ScalaOrder(5, 5, 5, "5", 5.0, 5),
      ScalaOrder(6, 6, 6, "6", 6.0, 6),
      ScalaOrder(7, 7, 7, "7", 7.0, 7),
      ScalaOrder(3, 3, 3, "3", 3.0, 3),
      ScalaOrder(4, 4, 4, "4", 4.0, 4)
    )

    //集合里面也有比较算子
    Sorting.quickSort(arr)/*(new Ordering[ScalaOrder] {
      override def compare(x: ScalaOrder, y: ScalaOrder) = x.getPrice.compare(y.getPrice)
    })*/

    for (elem <- arr) {
      println(elem)
    }

  }
}


case class ScalaOrder (
  @BeanProperty
  val user_id: Int = 0,
  @BeanProperty
  val order_id: Int = 0,
  @BeanProperty
  val goods_id: Int = 0,
  @BeanProperty
  val category_id: String = null,
  @BeanProperty
  val price: Double = .0,
  @BeanProperty
  val goods_num: Int = 0) extends Ordered[ScalaOrder] {
  override def compare(that: ScalaOrder): Int = -this.price.compare(that.price)
}

